package cn.tedu.myvrd.mapper;

import cn.tedu.myvrd.entity.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductMapper {
    @Insert("insert into product values(null,#{title},#{author},#{intro},#{imgurl},0,0,#{created},#{categoryId})")
    int insert(Product product);

    @Select("select id,title,author,intro,imgurl,viewCount,likeCount,created,categoryId from product")
    List<Product> selectAll();

    @Select("select id,title,intro,imgurl from product order by viewCount desc limit 0,4")
    List<Product> selectViewList();

    @Select("select id,title,intro,imgurl from product order by likeCount desc limit 0,4")
    List<Product> selectLikelist();

    @Select("select id,title,author,intro,imgurl,viewCount,likeCount,created from product where id=#{id}")
    Product selectById(int id);

    @Delete("delete from product where id=#{id}")
    void deleteById(int id);

    @Update("update product set likeCount=likeCount+1 where id=#{id}")
    void likeById(int id);

    @Update("update product set viewCount=viewCount+1 where id=#{id}")
    void viewById(int id);

    @Select("select id,title,author,intro,imgurl,viewCount,likeCount,created,categoryId from product where categoryId=#{cid}")
    List<Product> listById(int cid);

    @Select("select id,title,author,intro,imgurl,viewCount,likeCount,created,categoryId from product where title like concat('%',#{wd},'%')")
    List<Product> searchByWord(String wd);
}
